﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式.服务定位器模式
{
   public class ServiceLocator
    {
        private static Cache cache=new Cache();
        
        public static IService GetService(string jndiName)
        {
            IService service = cache.GetService(jndiName);
            if (service != null)
            {
                return service;
            }


            InitialContext context = new InitialContext();
            IService service1 = (IService)context.Lookup(jndiName);
            cache.AddService(service1);
            return service1;
        }
    }
}
